home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 29 (1992-07)(MegaDisc Digital Publishing)(AU)(Disk 1 of 2)[WB].zip
/
MegaDisc 29 (1992-07)(MegaDisc Digital Publishing)(AU)(Disk 1 of 2)[WB].adf
/
Programming
/
Asm_Startup
/
Startup_doc
< prev
next >
Wrap
Text File
|
1992-08-04
|
7KB
|
230 lines
startup.o
parsecommandline.o
Copyright © 1992
Michael McCallum
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WHAT'S HERE
You should find here:
1. startup.doc (this file)
2. startup.o (the linkable startup code for your programs!)
3. parsecommandline.o (separate parser, for those that want it)
INFORMATION
Before I get into the detailed description, etc., I'll make it clear now:
This is specifically aimed at the assembly language programmer!
Now, The Details!
I created this because I want to write utilities and things in assembly
language, and I wanted the command line to be pre-processed. Also, I only
needed CLI support. If this is what you are looking for, then you are in
the right place! Oh yeah, if you want to use the parser yourself, I have
provided the parser separately also.
What you now have in your hands, is an alternative startup code module
that you may use instead of Commodere's standard startup code. It is
intended for those CLI utilities and things that you write that do not need
WorkBench support, but need (relatively) intelligent command line parsing.
First off, I will not say that this is the be-all and end-all of startup
code. However, here is a list of its features:
+ Small (only about 316 bytes, including parser!)
+ Pre-parses the command line (wow!)
+ Options (of the form "-x") are separated from normal parameters
+ Pure code (can be made resident!!!)
+ The parser is also available to be called by the main program
To "use" the startup code, just link with this startup instead of
Commodore's startup.
USING THE STARTUP
When executed, the startup code checks for WorkBench execution. If it has
been executed by WorkBench, then the startup simply gets and returns the
WBmessage, and drops out.
If we get as far as realising we are a CLI process, then the command line
will be parsed, and then "main" will be called.
Simple really! Note, however, that Dos is not opened. This must be done
by your "main" code, if you need Dos. This is done so that the code is
capable of being made "resident".
Now, let's have a look at what the startup code passes to your "main"
code:
main (parv,parc,optv,optc)
A0 D0 A1 D1
A0: pointer to an argv-style array holding all non-option parameters
D0: the number of non-option parameters found
A1: pointer to an argv-style array holding all option parameters
D1: the number of option parameters found
Note: nothing is passed via the stack! I didn't design this stuff for C
programmers, you know! They already have their arguments separated, where
us assembly language programmers must do it ourselves. Here's to you, my
chums!
The arrays pointed to by A0 and A1 are terminated with a zero, making
(Ax)+ scanning of parameters and options easy. Also, the options have had
their "-" character stripped.
The memory used for the command-line is allocated and freed automatically
by the startup code.
THE PARSER
The parser is also provided separately, if you don't want to use my
alternative startup code, but still want the parser.
To use the parser, just include parsecommandline.o in your link line.
Using the parser is pretty simple. First, some definitions:
Parameters: A parameter is a sequence of characters separated by spaces.
Options: An option is a parameter beginning with a minus sign (-).
Options are placed in a separate array from parameters,
without their option specifier (-). This makes for easy
position-independent parsing of options. How you use them
is up to you!
Spaces: Spaces are used to separate parameters and options.
Quoting: When the parser encounters a quote (") on the command line,
it ceases to interpret special characters, including spaces
and the escape character, until it reaches another quote.
Escaping: To escape a character, precede it with a backslash (\), and
no interpreting of the character will be done. This can be
used to create a quote or space in a parameter. Escaping
and quoting also work on the option specifier (-),
allowing a parameter to begin with a minus sign.
Eg: [\-foo] or ["-foo"].
Control: A control character ($01-$1F) can be generated by
preceding the character which represents it with a
caret (^) character. Eg: [^j] will become control-j,
or linefeed ($0A). An actual control character in the
command line will be completely ignored.
Eg: [abc<TAB>def] will become [abcdef].
Big Example!
The command line
-foo name1 \-name2 -bar "name 3"
will become:
Parameter array (A0): ("->" means "pointer to")
->"name1",0
->"-name2",0
->"name 3",0
0
Option array (A1):
->"foo",0
->"bar",0
0
Note that the strings are zero terminated, as are the parameter and option
arrays themselves. This makes it easy to parse option using the "(An)+"
processor addressing mode.
Here is what you must pass to the parser:
ParseCommandLine (cline,clinelen,stringbuff,parambuff,optionbuff);
A0 D0 A1 A2 A3
A0: command line
D0: command line length
A1: buffer for parsed strings
A2: pointer to an argv-style array to hold all non-option parameters
A3: pointer to an argv-style array to hold all option parameters
ParseCommandLine returns:
A0: pointer to an argv-style array holding all non-option parameters
D0: the number of non-option parameters found
A1: pointer to an argv-style array holding all option parameters
D1: the number of option parameters found
IE: the same as what is passed to "main" by the startup code!
When your main code is called, the memory for the parameters, options and
bits is allocated for you, but should you call ParseCommandLine yourself,
you will have to allocate your own memory.
By the way, the code for the parser is only 150 bytes!
HOW TO
Just use this startup.o instead of Commodore's. Eg:
BLink FROM startup.o,mymaincode.o LIB Amiga.lib TO MyProgram
If you just want the parser:
BLink FROM astartup.o,mymaincode.o,parsecommandline.o
LIB Amiga.lib TO MyProgram
COPYRIGHT
This software is 100% my own work, and is copyright by me. However, I
give one and all the rights to copy and distibute this software as long as:
1. It is unmodified
2. It has it's documentation with it (this file).
3. Only a minimal fee, if any, be charged for media and time.
Also, this code may NOT be used in any commercial product without the
express permission of The Author (Michael McCallum).
FINAL WORDS
While I don't ask that you send me loadsadosh for this great wizz-bang bit
of contortery (is there such a word?), I am a student, and won't say no to
any contributions of money, disks, hardware, software, etc. that you nice
people want to send to me! (No bombs or such, please!) If you have any
comments, suggestions, or wicked jokes, send them to the address below!
ME
I can be contacted thus:
Michael McCallum
117 Morrison Rd
Midland WA 6056
or
09-274-3390
Thank you, and enjoy!
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>